import request from '../utils/request' // 引入封装过的axios
interface AdminLoginData {
  password: string
  username: string
}
// 登录返回接口
interface AdminLoginRes {
  token: string
  tokenHead: string
}
// 当前用户信息
interface AdminInfoRes {
  menus: []
}
// 组合登录和用户信息接口
interface ManageResult<T = {}> {
  code: number
  data: T
}

type PromiseRes<T> = Promise<ManageResult<T>>

// 登录返回token，需要username和password
const adminLoginAPI = (data: AdminLoginData): PromiseRes<AdminLoginRes> =>
  request.post('/admin/login', data)

// 获取当前登录用户信息
const getAdminUserInfoAPI = (): PromiseRes<AdminInfoRes> =>
  request.get('/admin/info')

// 根据用户名或姓名分页获取用户列表
const getAdminUserList = (data: any) => request.get('/admin/list', data)

export { adminLoginAPI, getAdminUserInfoAPI, getAdminUserList }
